#!/usr/bin/env python
# -*- coding: utf-8 -*-

class Cal:
    def add(self, a, b):
        return a + b

    def sub(self, a, b):
        return a - b

    def mul(self, a, b):
        return a * b

    def div(self, a, b):
        return a / b


import unittest


class TestCal(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        cls.cal = Cal()

    def test_add01(self):
        result = self.cal.add(1, 1)
        self.assertEqual(result, 2)

    def test_add02(self):
        result = self.cal.add(1.123, 3.1415)
        self.assertEqual(result, 4.2645)

    def test_add03(self):
        result = self.cal.add(6, -1)
        self.assertEqual(result, 5)


import HTMLTestRunner

if __name__ == '__main__':
    suite = unittest.TestSuite()
    testcases = unittest.TestLoader().loadTestsFromTestCase(TestCal)
    suite.addTests(testcases)

    f = open(r'D:\Python\APITest\classOnlineVideo\unittestdemo\report.html', 'wb')
    runner = HTMLTestRunner.HTMLTestRunner(stream=f, title='测试报告', description='测试报告详情')
    runner.run(suite)
